<!DOCTYPE html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
//, 'win', 'unix', 'android'
for (const platform of ['mac', 'win', 'unix', 'android']) {
  selection_test(
    [
      '<div contenteditable>',
        '<div>',
          '<span id="text">This is a paragraph.</span>',
        '</div>',
        '<br>',
      '</div>',
    ],
    selection => {
      assert_not_equals(window.eventSender, undefined,
        'this test requires eventSender');
      assert_not_equals(window.internals, undefined,
        'this test requires internals');

      internals.settings.setEditingBehavior(platform);

      const paragraph = selection.document.getElementById('text');
      const x = selection.computeLeft(paragraph) + paragraph.offsetWidth + 10;
      const y = selection.computeTop(paragraph) + paragraph.offsetHeight / 2;

      // Reset mouse state.
      eventSender.mouseMoveTo(0, 0);
      eventSender.mouseDown();
      eventSender.mouseUp();
      eventSender.leapForward(1000);

      // Right click
      eventSender.mouseMoveTo(x, y);
      eventSender.contextClick();

      // Kill the context menu
      eventSender.keyDown('Escape', null);
    },
    platform === 'mac'
        ? [
            '<div contenteditable>',
              '<div>',
                // MacOS selects end tag of DIV as word.
                '<span id="text">This is a paragraph.^</span>',
              '</div>',
              '|<br>',
            '</div>',
          ]
        : [
            '<div contenteditable>',
              '<div>',
                '<span id="text">This is a paragraph.|</span>',
              '</div>',
              '<br>',
            '</div>',
          ],
    `${platform}: context click at end of paragraph.`);
}
</script>
